dynamically menu

I have defined my own popup menu in the "lib\dxl\config\formalPopupFiles" directory.
It works fun. But I have one Problem now.
The menu items should be created dynamically:

for(i = 0; i < sizeof sTypes; i++)
{
createItem(alwaysOn, cbTest, sTypes[i], 'T', keyF2, modKeyNone, null, null, null, null)
}

How can I get Informations about the selected menuItem in the callback Function ‘cbTest’?

Thank you in advance
Brigitte
brineu - Wed Apr 13 07:28:09 EDT 2011

Re: dynamically menu
llandale - Wed Apr 13 15:16:53 EDT 2011

Forget the DXL for a second; you need to say in English how you expect that piece of code to know which menu items its supposed to create.

You also seem to be creating a menu with several items with different Labels, all activated with T, and all doing exactly the same callback. I suspect you will want a different flavor of "createItem", one that provides a dynamic Label and also provides for the execution of a specific DXL File. Perhaps this one:

void createItem(int mappingFunction(),string label,char mnemonic,char accelerator, int modifierKeyFlags,IconID icon_id,string tooltip,string helptext, string inactiveHelp,string dxlFile)

  • Louie

Re: dynamically menu
brineu - Thu Apr 14 03:26:19 EDT 2011

llandale - Wed Apr 13 15:16:53 EDT 2011
Forget the DXL for a second; you need to say in English how you expect that piece of code to know which menu items its supposed to create.

You also seem to be creating a menu with several items with different Labels, all activated with T, and all doing exactly the same callback. I suspect you will want a different flavor of "createItem", one that provides a dynamic Label and also provides for the execution of a specific DXL File. Perhaps this one:

void createItem(int mappingFunction(),string label,char mnemonic,char accelerator, int modifierKeyFlags,IconID icon_id,string tooltip,string helptext, string inactiveHelp,string dxlFile)

  • Louie

Sorry, but your proposal doesn’t solve my problem.
There is an enumaration attribute, which contains different types.
The user (project admin) can change the number of types and the name of types.
So, I must create the menu dynamically, depending on the enumeration attribute.
Now, I must know, which menuItem was selected. But I don’t know any way to find out this?!
It is impossible to pass a variable, neither to the callback Function, nor to a dxlFile

Brigitte

Re: dynamically menu
llandale - Thu Apr 14 18:01:45 EDT 2011

brineu - Thu Apr 14 03:26:19 EDT 2011
Sorry, but your proposal doesn’t solve my problem.
There is an enumaration attribute, which contains different types.
The user (project admin) can change the number of types and the name of types.
So, I must create the menu dynamically, depending on the enumeration attribute.
Now, I must know, which menuItem was selected. But I don’t know any way to find out this?!
It is impossible to pass a variable, neither to the callback Function, nor to a dxlFile

Brigitte

OK. <1> It seems you are reading an enumerated attribute that contains enough information for you to build a menu, which I now presume is on some dialog box. <2> Your individual menu items will take the labels defined in the attribute, but all will call either the same callback or same DXLFile; and that called code needs to know which one was selected.

<1a> Given the name of your attribute, this code will return the Type handle if its enumerated

AttrType   GetType(string  NameAD)
{    AttrDef  ad
        AttrType        at = null
 
        string          NameAT = ""
 
        ad     = find(mod, NameAD)
        if (null ad)
        {  return(at)                 // null
        }
        NameAT = ad.typeName
        at     = find(mod, NameAT)
        if (null at or at.type != attrEnumeration)
           at = null
        return(at)
}   // end GetType


<1b> Given a non-null enumerated AttrType, this code will cycle through all its enumerated values:

 

int    Count = at.size
        int     i
        string  Value
        for (i=0; i<SizeAT; i++)
        {  Value = at.strings[i]         }
           GoDoSomethingWithThis(Value)   // Menu code in here
        }


<2> I don't see how to do that either. Perhaps instead of a menu you can have a choice dialog element that the user selects from; you can then assign a callback to the element which includes the parameter for which one was selected and go from there.

But if indeed I HAD to use a menu, now that I think of it, I would start like this:
Create my callback function that accepts a string of the menu
Create a whole bunch of dummy functions, numbered 0-99. Each reads a global array representing the selected option, then calls the main function
.
<c> Reading the enumerated values creates the menu but also sticks the string value in the global array.

 

 

string Global[100]
int    NumGlobal = 0
 
void DoThisOption(string Option)
{   // based on Option, do what I'm supposed to do when the menu "Option" is selected
}
void DoOption00()
{  DoThisOption(Global[0])
}
void DoOption01()
{  DoThisOption(Global[1])
}
...
void DoOption99()
{  DoThisOption(Global[99])
}
void GoDoSomethingWithThis(int NumOption, string Option)
{  whatever
   if (NumOption == 0) createItem(... DoOption00, ...)
   elseif(NumOption == 1) createItem(..., DoOption01, ...)
   ...
   elseif(NumOption == 99) createItem(..., DoOption99, ...)
}
 
 
NumGlobal = at.size
int    i
string  Value
for (i=0; i<NumGlobal; i++)
{  if (i >=100) break // too many options
   Value = at.strings[i]           }
   Global[i] = Value
   GoDoSomethingWithThis(i, Value)   // Menu code in here
}

 

 

  • Louie

 

Re: dynamically menu
brineu - Fri Apr 15 04:44:23 EDT 2011

llandale - Thu Apr 14 18:01:45 EDT 2011

OK. <1> It seems you are reading an enumerated attribute that contains enough information for you to build a menu, which I now presume is on some dialog box. <2> Your individual menu items will take the labels defined in the attribute, but all will call either the same callback or same DXLFile; and that called code needs to know which one was selected.

<1a> Given the name of your attribute, this code will return the Type handle if its enumerated

AttrType   GetType(string  NameAD)
{    AttrDef  ad
        AttrType        at = null
 
        string          NameAT = ""
 
        ad     = find(mod, NameAD)
        if (null ad)
        {  return(at)                 // null
        }
        NameAT = ad.typeName
        at     = find(mod, NameAT)
        if (null at or at.type != attrEnumeration)
           at = null
        return(at)
}   // end GetType


<1b> Given a non-null enumerated AttrType, this code will cycle through all its enumerated values:

 

int    Count = at.size
        int     i
        string  Value
        for (i=0; i<SizeAT; i++)
        {  Value = at.strings[i]         }
           GoDoSomethingWithThis(Value)   // Menu code in here
        }


<2> I don't see how to do that either. Perhaps instead of a menu you can have a choice dialog element that the user selects from; you can then assign a callback to the element which includes the parameter for which one was selected and go from there.

But if indeed I HAD to use a menu, now that I think of it, I would start like this:
Create my callback function that accepts a string of the menu
Create a whole bunch of dummy functions, numbered 0-99. Each reads a global array representing the selected option, then calls the main function
.
<c> Reading the enumerated values creates the menu but also sticks the string value in the global array.

 

 

string Global[100]
int    NumGlobal = 0
 
void DoThisOption(string Option)
{   // based on Option, do what I'm supposed to do when the menu "Option" is selected
}
void DoOption00()
{  DoThisOption(Global[0])
}
void DoOption01()
{  DoThisOption(Global[1])
}
...
void DoOption99()
{  DoThisOption(Global[99])
}
void GoDoSomethingWithThis(int NumOption, string Option)
{  whatever
   if (NumOption == 0) createItem(... DoOption00, ...)
   elseif(NumOption == 1) createItem(..., DoOption01, ...)
   ...
   elseif(NumOption == 99) createItem(..., DoOption99, ...)
}
 
 
NumGlobal = at.size
int    i
string  Value
for (i=0; i<NumGlobal; i++)
{  if (i >=100) break // too many options
   Value = at.strings[i]           }
   Global[i] = Value
   GoDoSomethingWithThis(i, Value)   // Menu code in here
}

 

 

  • Louie

 

Thank you very mutch. But it seems to me, there is none good solution for my problem.
I have a procedure for every enumerated value. So, I think this way isn’t a good idea, there must give a better solution. But for a better solution I need in the callback function the label of menuItem or the int Variabel (position of menuItem). I hoped, that there is an undocumented perm. Now, I see, there is none.
I have no problems with enumerated attributes or create menues, what I want is a more elegant solution.
Many nevertheless thanks for your strives

Brigitte